package robotCross;

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;

import com.supermap.desktop.implement.SmMenu;
import com.supermap.desktop.implement.SmMenuItem;

import abbot.finder.matchers.AbstractMatcher;
import abbot.util.AWT;

/** Provides matching of Components by component tip. */
public class TipMatcher extends AbstractMatcher {
	private String tip;

	/**
	 * Construct a matcher that will match any component that has explicitly
	 * been assigned the given <code>tip</code>. Auto-generated tips (e.g.
	 * <code>win0</code>, <code>frame3</code>, etc. for AWT (native) based
	 * components will not match.
	 */
	public TipMatcher(String tip) {
		this.tip = tip;
	}

	/**
	 * @return whether the given component has been explicitly assigned the tip
	 *         given in the constructor.
	 */
	public boolean matches(Component c) {
		String ctip = "";
		if (c instanceof JComponent) {
			ctip = ((JComponent) c).getToolTipText();
		}
		if (tip == null)
			return ctip == null || AWT.hasDefaultName(c);
		return stringsMatch(tip, ctip);
	}

	public String toString() {
		return "Tip matcher (" + tip + ")";
	}
}
